package com.hehui.partimejob.js.ques;

import android.content.Context;
import android.content.Intent;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import com.google.gson.Gson;
import com.hehui.partimejob.BaseActivity;
import com.hehui.partimejob.activity.ques.AddQuesActivity;
import com.hehui.partimejob.activity.ques.EditQuesItemActivity;
import com.hehui.partimejob.js.BaseJSInterface;
import com.hehui.partimejob.js.JSBean.Ques;
import com.hehui.partimejob.uitls.LiveDataBus;

public class EditQuesJSFace extends BaseJSInterface {


    public EditQuesJSFace(BaseActivity context) {
        super(context);
    }

    @JavascriptInterface
    public void goToEditChoose(String item) {
        Intent intent = new Intent(context, EditQuesItemActivity.class);
        intent.putExtra("type", item);
        context.startActivity(intent);
    }

    @JavascriptInterface
    public void back() {
        ((BaseActivity) context).finish();
    }

    @JavascriptInterface
    public void goToEditHead(String title, String wel) {
        Intent intent = new Intent(context, AddQuesActivity.class);
        intent.putExtra("title", title);
        intent.putExtra("wel", wel);
        ((BaseActivity) context).startActivity(intent);
    }

    @JavascriptInterface
    public void goToEditFoot(String end) {
        Intent intent = new Intent(context, AddQuesActivity.class);
        intent.putExtra("end", end);
        context.startActivity(intent);
    }

    @JavascriptInterface
    public void release(String allData) {
        Ques ques = new Gson().fromJson(allData, Ques.class);
        log(ques.getQues_end());
    }

    @JavascriptInterface
    public void hint(String msg) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }

    @JavascriptInterface
    public void show() {
        runOnUIThread();
    }
}
